/**
 * 20220112：为适应XR改造的Drag做了简化
  * 20220304:[require] to [import]...jordia
  * 20220607:增加设置camera的方法
 */
import {MathUtils} from 'three';

/**
 * 拖动配置基类
 * @param values {object}
 threshold:0.1 拾取阈值
 rangeSq:10000 拖动范围（平方）具体配置实现
 */
export default class DragConfig{
    constructor(values={}){
        this._values=values;
        this._init();
    }

    /**
     * 获取配置类型
     * @returns {string}
     */
    get type(){
        return 'drag-config';
    }

    /**
     * 获取ID
     * @returns {null|string}
     */
    get uuid(){
        return this._uuid;
    }

    /**
     * 获取约束
     * @returns {*|null}
     */
    get limit(){
        return this._limit;
    }

    /**
     * 设置拖动的约束
     * @param limit
     */
    set limit(limit){
        this._limit=limit;
    }

    /**
     * 将当前的约束设为记忆点
     */
    get remember(){
        this._baseLimit=this._limit;
    }

    /**
     * 恢复到记忆点约束
     */
    get recall(){
        this._limit=this._baseLimit;
    }

    //-----------------------------------------------------------------------------------------------

    get threshold(){
        return this._threshold;
    }
    set threshold(number){
        this._threshold=number;
    }
    get rangeSq(){
        return this._rangeSq;
    }
    set rangeSq(number){
        this._rangeSq=number;
    }

    //-----------------------------------------------------------------------------------------------

    /**
     * 检测对象类型是否符合当前配置
     * @param object
     * @returns {boolean}
     */
    checkType(object){
        console.warn('needs override this method!');
        return false;
    }

    /**
     * 当前配置类型对象的对比函数
     * @param a
     * @param b
     * @returns {boolean}
     */
    compare(a,b){
        console.warn('needs override this method!');
        return true;
    }

    /**
     * 检测对象是否拾取成功
     * @param object
     * @param raycaster
     * @returns {boolean}
     */
    intersectObject(object,raycaster){
        console.warn('needs override this method!');
        return false;
    }

    /**
     * 设置拖动开始状态
     * @param intersect
     * @param object
     */
    setDragStart(intersect,object){
        console.warn('needs override this method!');
    }

    /**
     * 设置拖动过程状态
     */
    setDragMove(){
        console.warn('needs override this method!');
    }

    setCamera(camera){
        this._camera=camera;
    }

    /**
     * 销毁
     */
    dispose(){
        this._limit.dispose();
        this._threshold=null;
        this._rangeSq=null;
        this._uuid=null;
        this._limit=null;
        this._baseLimit=null;
    }

    /**
     * 对象的拖动行为
     * @param object
     * @param wldPos
     * @param callback
     * @private
     */
    _moveObject(object, wldPos,callback){}

    _init(){
        this._initVariable();
    }
    _initVariable(){
        this._threshold=this._values.threshold||0.1;
        this._rangeSq=this._values.rangeSq||1e6;
        this._uuid=MathUtils.generateUUID();
        this._limit=null;
        this._baseLimit=null;
        this._camera=null;
    }
}